import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class BackupService extends BaseService<any> {
  private readonly logger = new Logger(BackupService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * backupCode
   * 对应 PHP: BackupService_admin::backupCode()
   * 逻辑类型: undefined - undefined
   */
  async backupCode() {
    // 基于PHP真实逻辑: backupCode
    // PHP原文: $backup_dir = $this->upgrade_dir . $this->upgrade_task[ 'key' ] . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'code' . DIRECTORY_SEPARATOR;...
const backup_dir = this.upgrade_dir . this.upgrade_task[ 'key' ] . DIRECTORY_SEPARATOR  + 'backup' . DIRECTORY_SEPARATOR  + 'code' . DIRECTORY_SEPARATOR;

        // 创建目录
        dir_mkdir(backup_dir);

        // 备份admin
        dir_copy(this.root_path  + 'admin', backup_dir  + 'admin', exclude_dirs: [ '.vscode', 'node_modules', 'dist' )];

        // 备份uni-app
        dir_copy(this.root_path  + 'uni-app', backup_dir  + 'uni-app', exclude_dirs: [ 'node_modules', 'dist' )];

        // 备份web
        dir_copy(this.root_path  + 'web', backup_dir  + 'web', exclude_dirs: [ 'node_modules', '.nuxt', '.output', 'dist' )];

        // 备份niucloud全部代码
        const niucloud_dir = backup_dir  + 'niucloud' . DIRECTORY_SEPARATOR;

        dir_copy(this.root_path  + 'niucloud', niucloud_dir, exclude_dirs: [ 'runtime', 'upload' ), exclude_files: ..user.ini];

        return true;
    }
}
  }
}
